<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>骨医快线</title>
    <link href="../../css/mui.plus.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../../css/mui.min.css" />
    <style>
    	/*背景色修正*/
    	body {
    		background-color: #fff;
    	}
    	/*固定登陆框位置*/
    	.oe-login {
		    position: absolute;
		    width: 70%;
		    top: 40%;
		    left: 15%;
		    background-color: #fff;
		}
		.mui-input-group.oe-input-login {
			width: 100%;
    	}
    	.oe-login .mui-input-group > .mui-input-row {
    		background-color: #fff;
    	}
    	.oe-login input{
    		text-align: left;
    	}
    	/*各种按钮适配*/
    	.oe-btn-block {
		    display: block;
		    width: 100%;
		    margin-bottom: 10px;
		    font-size: 18px;
		}
		.mui-btn-link {
		    color: #666;
		}
		/*logo框适配*/
		.pat-logo-wrap {
			z-index: 2;
			position: absolute;
			top: -190px;
			width: 100%;
			height: 150px;
			
			text-align: center;
		}
		.pat-logo-wrap>img {
			width: auto;
			height: 70%;
			margin: 0 auto;
		}
		.pat-logo-wrap>p {
			font-size: 24px;
			color: #666;
		}
		
    </style>
</head>
<body>
	<div class="mui-content oe-login">
		<form class="mui-input-group">
			<!--<div class="mui-input-row">
				<input id="accInp" type="text" class="mui-input-clear" placeholder="手机号" maxlength="11">
			</div>
			<div class="mui-input-row" style="margin-top: 10px;">
				<input id="pwdInp" type="password" class="mui-input-password" placeholder="密码">
			</div>-->
			
			<div class="pat-logo-wrap">
				<img src="../../images/logo.png" alt="" />
				<p>骨医快线</p>
			</div>
			
			<div class="mui-input-group oe-input-login">
				<div class="mui-input-row">
					<label>
						<span class="mui-icon mui-icon-chatboxes"></span>
					</label>
					<input id="accInp" class="mui-input-clear" type="text" placeholder="用户名">
				</div>
				
				<div class="mui-input-row mui-input-password">
					<label>
						<span class="mui-icon mui-icon-locked"></span>
					</label>
			    	<input id="pwdInp" type="password" class="mui-input-password" placeholder="密码">
					<!--<input  id="pwdInp" type="password" class="mui-input-password" data-input-password="8"><span class="mui-icon mui-icon-eye"></span>-->
				</div>
			</div>
			
			<button id="loginBtn" class="mui-btn mui-btn-primary oe-btn-block" onclick="return false;" style="margin-top: 15px;">登&nbsp;&nbsp;&nbsp;录</button>&nbsp;&nbsp;
			<button id="regBtn" type="button" class="mui-btn mui-btn-link">
				注册
			</button>
			<button id="forgetBtn" type="button" class="mui-btn mui-pull-right mui-btn-link">
				忘记密码？
			</button>
		</form>
		
	</div>
    <script src="../../js/mui.min.js"></script>
    <script src="../../js/app.js"></script>
    <script src="../../js/lib/md5.js"></script>
    <script type="text/javascript" charset="UTF-8">
		(function($, doc){
			var login = app.login;
			var storage = app.storage;
			var regtelPage = {};
			//页面初始化，传入相关参数
      		 
      		$.plusReady(function(){
      			// 页面设置
      			// ============================================================
      			plus.screen.lockOrientation("portrait-primary");
      			
      			// 更新cid
//    			if(app.storage.getUserId()){
//    				var drId = app.storage.getUserId(),
//    					cId = plus.push.getClientInfo().clientid;
//    				console.log(JSON.stringify(plus.push.getClientInfo()));
//    				app.net.post('doctors/update.json', {dr_id: drId, dr_cid: cId}, function(data){
//    					
//    				});
//    			}
      			 
      			// 版本更新检测
      			app.net.get('c_app_version/check_version', {cur_app_num: plus.runtime.version, os_type: plus.os.name.toUpperCase()}, function(data){
      				if(data && data.code === '100' && data.data.ver_upgrade_type === 'RECOMMEND'){
  						$.confirm(data.data.ver_desc, '神医，看这里哟', ['更新', '取消'], function(e){
      						if(e.index === 0){
      							plus.runtime.openURL(data.data.ver_app_url); 
      						}
      					}) 
      				}else if(data && data.code === '100' && data.data.ver_upgrade_type === 'FORCE'){
      					$.alert(data.data.ver_desc, '神医，看这里哟', '更新', function(){
      						plus.runtime.openURL(data.data.ver_app_url); 
      					});
      				}
      			});
      			// 参数定义
      			// ============================================================
      			var settings = storage.getSettings();
      			var state = storage.getState();
      			var mainPage = $.preload({
      				"id": 'main',
      				"url": '../main.html'	
      			});
      			var toMain = function() {
      				$.fire(mainPage, 'gohome', null);
      				var pages = plus.webview.all();
      				for(var i in pages){
						$.fire(pages[i], 'start', null);
					}
      				setTimeout(function(){
      					$.openWindow({
      						id: 'main',
      						show: {
      							aniShow: 'zoom-out'
      						},
      						waiting: {
      							autoShow: false
      						}
      					}); 
      				},100);
      			}; 
      			var loginBtn = doc.getElementById('loginBtn'),
      				regBtn = doc.getElementById('regBtn'),
      				forgetBtn = doc.getElementById('forgetBtn'),
      				accInp = doc.getElementById('accInp'),
      				pwdInp = doc.getElementById('pwdInp');
      			
      			// 事件装载
      			// ===================================================================
      			
      			// 监听页面显示事件，由于webview中show事件的不确定性，此为临时解决方案
      			window.addEventListener('start', function(){
      				accInp.value = '';
      				pwdInp.value = '';
      			});
      			
      			// 登录按钮
      			loginBtn.addEventListener('tap', function(event) {
					var loginInfo = {
						account: accInp.value,
						password: hex_md5(pwdInp.value)
					};
					login.login(loginInfo, function(err) {
						if (err) {
							plus.nativeUI.toast(err);
							return;
						}
						app.bc();
						toMain();
						$.toast('登录成功');
					});
				});
				
				// 注册按钮点击事件
	      		regBtn.addEventListener('tap', function(event) {
						$.openWindow({
							url: 'reg-tel.html',
							waiting: {
								autoShow: false
							},
							extras: {
								a: {
									b: 'test',
									c: 'test1'
								}
							},
							show: {
								aniShow: 'slide-in-bottom'
							}
						});
					}, false);
				
					// 忘记密码
					$('.mui-content').on('tap', '#forgetBtn', function(){
						$.openWindow({
							url: 'forget.html',
							waiting: {
								autoShow: false
							}
						})
					});
					
      				if(typeof storage.getUserId() !== 'undefined'){
						$.openWindow({
      						id: 'main',
      						show: {
      							aniShow: 'zoom-out'
      						},
      						waiting: {
      							autoShow: false
      						}
      					}); 
					}
					   
	      		});
	      		
      	}(mui, document));
    </script>
</body>
</html>